package org.stone.project.common.config;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.stone.project.common.pojo.constant.SpringConstant;

@Configuration
public class JacksonConfig {
    @Bean
    @Primary
    public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
        return builder.createXmlMapper(false).build();
    }


    @Bean(SpringConstant.ADD_CLASS_OBJECT_MAPPER)
    public ObjectMapper addClassObjectMapper(Jackson2ObjectMapperBuilder builder){
        ObjectMapper objectMapperUse = builder.createXmlMapper(false).build();
        objectMapperUse.activateDefaultTyping(objectMapperUse.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
        return objectMapperUse;
    }
}
